package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueAfficheDao;
import com.prs.crm.domain.doc.IssueAffiche;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.Affiche;
import com.prs.crm.service.doc.IssueAfficheService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.AfficheService;

public class IssueAfficheServiceImpl extends BaseServiceImpl<IssueAffiche,IssueAfficheDao> implements IssueAfficheService{
	private PersonService personService;
	private AfficheService afficheService;
	
	@Override
	public void submitIssueAffiche(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<Affiche> affiches =this.getAfficheService().getAfficheByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		
		for(Person person : persons) {
			for(Affiche affiche : affiches) {
				IssueAffiche issue = new IssueAffiche();
				issue.setReceivePerson(person);
				issue.setAffiche(affiche);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				
				this.getDao().save(issue);
			}
		}
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}

	public void setAfficheService(AfficheService afficheService) {
		this.afficheService = afficheService;
	}

	public AfficheService getAfficheService() {
		return afficheService;
	}

	@Override
	public Collection<IssueAffiche> getValidIssueAffiche(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueAffiche(person);
	}

}
